function m2_mean = model_m2_mean(b,time,parameters)
C2 = b(1);
sigma2 = b(2)*b(1);
L = parameters(1);
mode = parameters(2);
m2_mean = zeros(size(time));
for i = 1:length(time)
    m2 = 0.0;
    for m = 0:mode
        for n = 0:mode
            if(m~=0||n~=0)
                lambda = -4.0*C2*(m^2+n^2);
                temp1 = exp(2*lambda*time(i));
                Km1 = 4*sin(pi*m/L)^2/(pi^2);
                Km2 = Km1;
                Km3 = Km1;
                Km4 = Km1;
                if m==0||2*m==L||n==0||2*n==L 
                    Km1 = 0.0;
                end
                if m==0
                    Km2 = 0.0;
                end
                if m==0||2*m==L
                    Km3 = 0.0;
                end
                if n==0||2*n==L||m==0
                    Km4 = 0.0;
                end                    
                m2 = m2+(Km1+Km2+Km3+Km4)*sigma2*(temp1-1)/(2*lambda);
            end
        end
    end
    m2_mean(i) = m2;
end